﻿/*  
    Copyright (C) <2007-2013>  <Kay Diefenthal>

    ArgusTv.UI.MediaCenter is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    ArgusTv.UI.MediaCenter is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with ArgusTv.UI.MediaCenter.  If not, see <http://www.gnu.org/licenses/>.
*/

using System;
using System.Collections;

using ArgusTV.UI.MediaCenter.Models;
using Microsoft.MediaCenter.UI;

namespace ArgusTV.UI.MediaCenter.Views
{
    public class SearchView : ModelItem
    {
        private IList _content;
        private EditableText _searchTerm;
        private OnDemandOfferModel _info;
        public virtual EditableText SearchTerm
        {
            get { return _searchTerm; }
            set
            {
                if (_searchTerm != value)
                {
                    if (_searchTerm != null)
                        _searchTerm.Submitted -= OnSearchTermChanged;
                    _searchTerm = value;
                    if (_searchTerm != null)
                        _searchTerm.Submitted += OnSearchTermChanged;
                    OnSearchTermChanged(_searchTerm, EventArgs.Empty);
                    FirePropertyChanged("SearchTerm");
                }
            }
        }

        public IList Content
        {
            get { return _content; }
            set
            {
                if (_content != value)
                {
                    _content = value;
                    FirePropertyChanged("Content");
                }
            }
        }

        public OnDemandOfferModel Info
        {
            get { return _info??(_info= new OnDemandOfferModel()); }
            set { _info = value; FirePropertyChanged("Info"); }
        }

        public void FocusedItem(SearchCommand command)
        {
            OnFocusChanged(command, EventArgs.Empty);
        }

        public event EventHandler SearchTermChanged;
        public event EventHandler FocusChanged;

        protected virtual void OnSearchTermChanged(object sender, EventArgs args)
        {
            if (SearchTermChanged != null)
                SearchTermChanged(sender, EventArgs.Empty);
        }

        protected virtual void OnFocusChanged(object sender, EventArgs args)
        {
            if (FocusChanged != null)
                FocusChanged(sender, EventArgs.Empty);
        }
    }
}